package com.yanxibao.controller;

import com.yanxibao.bean.University;
import com.yanxibao.common.Result;
import com.yanxibao.dto.PageQueryDTO;
import com.yanxibao.service.UniversityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 院校;(_university)表控制层
 */
@Api(tags = "院校对象功能接口")
@RestController
@CrossOrigin
@RequestMapping("/University")
public class UniversityController {

    @Resource
    private UniversityService universityService;


    /**
     * 通过ID查询单条数据
     *
     * @param universityId 主键
     */
    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/getById/{universityId}")
    @ResponseBody
    public Result<University> queryById(@PathVariable("universityId") String universityId) {
        return universityService.queryById(universityId);
    }

    /**
     * 分页查询
     */
    @ApiOperation("分页查询")
    @PostMapping("/getPage")
    @ResponseBody
    public Result<PageQueryDTO<University>> pageQuery(@RequestParam("current") Integer current,
                                          @RequestParam("size") Integer size,
                                          @RequestBody University university) {

        return universityService.pageQuery(university, current, size);
    }

    /**
     * 动态查询所有
     *
     * @param university 学校对象
     */
    @ApiOperation("动态查询所有")
    @PostMapping("/all")
    @ResponseBody
    public Result<List<University>> queryAll(@RequestBody University university) {

        return universityService.queryAll(university);
    }

    /**
     * 新增数据
     *
     * @param university 实例对象
     */
    @ApiOperation("新增数据")
    @PostMapping("/add")
    @ResponseBody
    public Result<University> add(@RequestBody University university) {
        return universityService.insert(university);
    }

    /**
     * 更新数据
     *
     * @param university 实例对象
     */
    @ApiOperation("更新数据")
    @PutMapping("/update")
    public Result<University> update(@RequestBody University university) {
        return universityService.update(university);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     */
    @ApiOperation("通过主键删除数据")
    @DeleteMapping("/del/{id}")
    public Result<Boolean> deleteById(@PathVariable String id) {
        return universityService.deleteById(id);
    }
}